//
//  ACEQuestionsViewController.m
//  ACE
//
//  Created by zhangtao on 2018/8/7.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "ACEQuestionsViewController.h"
#import "ACEQuestionsNavTitleView.h"
#import "ACEQuestionsTableViewCell.h"
#import "ACESelectPickerView.h"

#import "ACEQuestionSubjectViewController.h"

@interface ACEQuestionsViewController ()
@property(nonatomic,strong)UIView *coverView;
@end

@implementation ACEQuestionsViewController
{
    ACEQuestionsNavTitleView *titleView;
    ACESelectPickerView *pickerView;
    
}

-(ACESelectPickerView *)pickerView{
    if (!pickerView) {
        pickerView = [[ACESelectPickerView alloc]initWithFrame:CGRectMake(0, navHeight, ACEWidth, 200)];
        pickerView.sourceValue = titleView.title;
        pickerView.dataArray = @[@"加伦比亚大学",@"哈佛大学",@"纽约大学",@"哈斯顿职业技术学院",@"加伦比亚大学",@"哈佛大学",@"纽约大学",@"哈斯顿职业技术学院",@"加伦比亚大学",@"哈佛大学",@"纽约大学",@"哈斯顿职业技术学院"];
        
        __weak typeof(titleView)weakTitleView = titleView;
        WEAKSELF;
        pickerView.SelectPickerCallBack = ^(NSString *str) {
            weakTitleView.title = str;
            [weakSelf selectSchool];
        };
    }
    return pickerView;
}

-(UIView *)coverView{
    if (!_coverView) {
        _coverView = [[UIView alloc]initWithFrame:CGRectMake(0, navHeight-2, ACEWidth, ACEHeight)];
        _coverView.backgroundColor = RGB(230, 230, 230, .5);
    }
    return _coverView;
}

-(ACEQuestionsNavTitleView *)titleView{
    if (!titleView) {
        titleView = [[ACEQuestionsNavTitleView alloc]initWithFrame:CGRectMake(30, 0, ACEWidth-60, 40)];
        WEAKSELF;
        titleView.QuestionsNavtitleCallBack = ^{
            [weakSelf selectSchool];
        };
    }
    return titleView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[ACEQuestionsTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.navigationItem.titleView = self.titleView;
    [self showLeftHome];
}

-(void)selectSchool{
    if (_coverView) {
        [_coverView removeFromSuperview];
        _coverView = nil;
        [pickerView removeFromSuperview];
        pickerView = nil;
    }else{
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [window addSubview:self.coverView];
        [window addSubview:self.pickerView];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //138:23
    return ACEWidth/(690/115);
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ACEQuestionsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[ACEQuestionsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ACEQuestionSubjectViewController *subject = [[ACEQuestionSubjectViewController alloc]init];
    subject.subjectName = @"题目标题";
    subject.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:subject animated:YES];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
